from django.contrib import admin
from .models import Products, Tasks

# Register your models here.


class ProductsAdmin(admin.ModelAdmin):
    list_display = ['id', 'asin', 'name', 'price', 'currency', 'brand', 'seller', 'reviews', 'reviews_count', 'bought_last_month', 'seller_rank', 'image_path',
                    'conn_tech', 'connector_type', 'ports', 'compatiable_phones', 'compatible_devices', 'voltage', 'wattage', 'fast_charge', 'url', 'create_time']
    # 设置分页，每页显示10条
    list_per_page = 10

    # 产品名称只显示前50字符
    def name(self, obj):
        return obj.name[:30]


class TasksAdmin(admin.ModelAdmin):
    list_per_page = 10
    fieldsets = (
        (None, {
            'fields': ('id', 'name', 'kw', 'type', 'start_time', 'end_time')
        }),
        ('定时任务', {
            'fields': ('cron_day', 'cron_weekday', 'cron_hour', 'cron_minute')
        }),
        (None, {
            'fields': ('status', 'create_time')
        })
    )
    readonly_fields = ('id', 'create_time')


admin.site.site_header = "Amazonbot数据管理后台"
admin.site.register(Products, ProductsAdmin)
admin.site.register(Tasks, TasksAdmin)
